﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BRM.DataAccess
{
    public class ConfigHelper
    {
        public string sPath;
        public string sName;
        public string sPass;
        public string sServername;
        public string sServerpass;
        public string sDbpath;
        public string sDbname;

        public void ReadConfig(string configpath)
        {   
            //Đọc file config
            AQFramework.Configurations AQconfig = new AQFramework.Configurations(configpath,true);
            sPath = AQconfig.ReadAppSettings("Default_path");
            sName = AQconfig.ReadAppSettings("Name");
            sPass = AQconfig.ReadAppSettings("Pass");
            sServername = AQconfig.ReadAppSettings("Server_name");
            sServerpass = AQconfig.ReadAppSettings("Server_pass");
            sDbpath = AQconfig.ReadAppSettings("DB_path");
            sDbname = AQconfig.ReadAppSettings("DB_name");  
        }

        public void UpdateConfig(string sNew_name, string sNew_path, string sNew_pass, string sNew_servername,string sNew_serverpass,string sNew_dbname,string sNew_username,string sConfigpath,string sAutoDate,string sAutoTime)
        {
            //Update file config
            AQFramework.Configurations AQconfig = new AQFramework.Configurations(sConfigpath, true);
            AQconfig.UpdateAppSettings("Default_path",sNew_path);
            AQconfig.UpdateAppSettings("Name",sNew_name);
            AQconfig.UpdateAppSettings("Pass",sNew_pass);
            AQconfig.UpdateAppSettings("Server_name",sNew_servername);
            AQconfig.UpdateAppSettings("User_pass",sNew_serverpass);
            AQconfig.UpdateAppSettings("DB_name", sNew_dbname);
            AQconfig.UpdateAppSettings("User_name", sNew_username);
            AQconfig.UpdateAppSettings("Auto_date", sAutoDate);
            AQconfig.UpdateAppSettings("Auto_Time", sAutoTime);
        }
    }
}
